package com.house.customer.service;

import java.util.List;

import org.hibernate.type.TrueFalseType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.house.customer.dao.ICustomerDao;
import com.house.customer.entity.Customer;

@Service
@Transactional
public class CustomerService implements ICustomerService{

	@Autowired
	private ICustomerDao customerDao;

	@Override
	public void saveOrUpdate(Customer customer) {
		customerDao.save(customer);
	}
	
    @Override
	public void delete(Customer customer) {
    	customerDao.delete(customer);
	}

	@Override
	public void delete(List<Long> ids) {
		List<Customer> customers=(List<Customer>) customerDao.findAll(ids);
		if(customers!=null) {
			customerDao.delete(customers);
		}
	}
	
	@Transactional(readOnly=true)
	public Customer findOne(Long id) {
		return customerDao.findOne(id);
	}
	
	@Transactional(readOnly=true)
	public List<Customer> findAll() {
		return (List<Customer>) customerDao.findAll();
	}

	@Transactional(readOnly=true)
	public Page<Customer> findAll(Specification<Customer> spec, Pageable pageable) {
		return customerDao.findAll(spec, pageable);
	}

	



}
